# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=bencode
pkgname=haskell-bencode
pkgver=0.6.1.1
pkgrel=178
pkgdesc="Parser and printer for bencoded data."
url="https://hackage.haskell.org/package/${_hkgname}"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-transformers-compat')
makedepends=('ghc' 'haskell-hspec' 'haskell-quickcheck')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('e2f4c312923412a47cbea62caf6e001e30418946165405f2cd9d77f06c13ff2846b352e28ca6cbbfce3bf236fb42f0b108442b17e2b0e8bac702af6d6a114f09')

prepare() {
    cd $_hkgname-$pkgver
    echo -e "import Distribution.Simple\nmain = defaultMain" > Setup.hs
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
